#include "ForumStruct.h"
#include "ImgMgr.h"
#include "Level.h"
#include "RessourceMgr.h"
#include "WorkerUnit.h"

ForumStruct::ForumStruct() : Struct()
{
}

bool ForumStruct::addWorker(WorkerUnit *worker) const
{
	return false;
}

void ForumStruct::init(const sf::Vector2f position, const int team, ImgMgr *imageManager)
{
	m_skin = imageManager->getSprite(9);
	m_skin.setScale(6, 6);
	m_vie = 10;
	m_nombreMaxWorker = 0;
	Struct::init(sf::Vector2f((float)random((int)position.x - 8, (int)position.x + 8), (float)random((int)position.y - 8, (int)position.y + 8)), team, imageManager);
}

void ForumStruct::maj(Level *level, RessourceMgr *ressourceMgr)
{
	if(m_clockUnit.getElapsedTime().asMilliseconds() > 500)
	{
		if(!ressourceMgr->popIsHigh() && ressourceMgr->getFood() > 0)
		{
			int posUnitX = random((int)getPosition().x, (int)getPosition().x + (int)m_skin.getGlobalBounds().width);
			int posUnitY = (int)getPosition().y + (int)m_skin.getGlobalBounds().height;
			level->addUnit(new WorkerUnit(), sf::Vector2f((float)posUnitX, (float)posUnitY), m_idTeam);
			ressourceMgr->modifyFood(-1);
		}
		m_clockUnit.restart();
	}
	int e = 0;
	Struct::maj(level, ressourceMgr);
}